<template>
	<view class="deep">
		<view class="scroll_header"></view>
		
			<scroll-view scroll-y="true" :style="{height: scrollHeight}">
				<view class="mt-5" v-if="u_loadmore">
					<u-loadmore status="loading" icon-type="circle" />
				</view>
				<view v-else>
				<view class="addPhoto m-2  bg-white py-2 rounded-20">
					<view class="d-flex flex-column a-center pt-2 border-bottom mx-3 ">
						<view class="icon_gray bg-light-secondary d-flex flex-column j-center a-center rounded-20" >
							<image-cropper :src="tempFilePath" @confirm="confirm" @cancel="cancel"></image-cropper>
							<view class="crop rounded-20 position-relative"  @tap="unloadImg">
								<image  mode="aspectFit" :src="cropFilePath?cropFilePath:basic_detail.img.url" class="img"></image>
								<view class="font drawing text-center">主图</view>
							</view>
						</view>
						<view class="font py-2">添加需要图片上传</view>
					</view>
					<view class="">
						<view class="ml-3 py-2">
							<textarea v-model="goods_name" placeholder-class="font-md" @blur="chang_blur" @focus="chang_focus" @input="change" maxlength="59"></textarea>
							<view class="font d-flex j-end mr-2 mt-5">{{num}}/{{count}}</view>
						</view>
					</view>
				</view>
				<view class="">
					<view class="mx-2 mb-2 bg-white rounded-20" v-if="!userinfo.is_merchant">
						<view class="ml-3">
							<view class="border-bottom clazz d-flex j-sb a-center" @click="goodsClass">
								<view class="">平台分类</view>
								<view class="d-flex a-center j-center mr-2">
									<text class="mr-2 mr-1 text-light-muted">{{!clazzList.cat_name?basic_detail.category_name:clazzList.cat_name}}</text>
									<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
								</view>
							</view>
						</view>
					</view>
					<view class="mx-2 mb-2 bg-white rounded-20" v-else>
						<view class="ml-3">
							<view class="border-bottom clazz d-flex j-sb a-center" @click="goodsClass">
								<view class="">平台分类</view>
								<view class="d-flex a-center j-center mr-2">
									<text class="mr-2 mr-1 text-light-muted">{{!clazzList.cat_name?basic_detail.category_name:clazzList.cat_name}}</text>
									<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
								</view>
							</view>
							<view class=" clazz  d-flex j-sb a-center" @click="goodsShop">
								<view class="">店铺分类</view>
								<view class="d-flex a-center j-end mr-2 w-50">
									<text class="mr-2  mr-1 text-light-muted ellipsis-1">{{!shopList.cat_name?basic_detail.merchant_category_name:shopList.cat_name}}</text>
									<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				
				<view class="mx-2 mb-2 bg-white rounded-20">
					<view class="ml-3">
						<view class="border-bottom a-center  py-3 d-flex j-sb clazz">
							<view class="">商品货号</view>
							<view class="mr-2">
								<input type="digit" placeholder="请输入商品货号" @input="sn_input" @blur="sn_blur" @focus="sn_focus"  class="text-right"  v-model="goods_sn"  placeholder-class="font-29 mr-1 d-flex j-end"/>
							</view>
						</view>
						<view class=" py-3 a-center border-bottom d-flex j-sb clazz">
							<view class="">单位条形码</view>
							<view class="mr-3 flex-1 d-flex j-end a-center">
								<input type="text" placeholder="请输入单位条形码" @input="bar_input" @blur="bar_blur" @focus="bar_focus"  v-model="bar_code" class="text-right mr-1" placeholder-class="d-flex font-29 j-end" />
								<u-icon name="scan" @click="scanCode" color="#222222" size="50"></u-icon>
							</view>
						</view>
						<view class=" py-3 a-center  d-flex j-sb clazz border-bottom">
							<view class="">商品单位</view>
							<view class="mr-2">
								<input type="text" placeholder="请输入商品单位" @input="unit_input" @blur="unit_blur" @focus="unit_focus" class="text-right"  v-model="goods_unit" placeholder-class="font-29 mr-1 d-flex j-end"/>
							</view>
						</view>
					</view>
				</view>
				<view class="mx-2 mb-2 bg-white rounded-20">
					<view class="ml-3">
						<view class=" py-3 a-center  d-flex j-sb clazz">
							<view class="">库存</view>
							<view class="mr-2">
								<input type="digit" placeholder="请输入库存" class="text-right" v-model="store" placeholder-class="font-29 mr-1 d-flex j-end" @blur="store_blur" @focus="store_focus" @input="add_store" />
							</view>
						</view>
					</view>
				</view>
				<view class="mx-2 mb-2 bg-white rounded-20">
					<view class="ml-3">
						<view class=" py-3 a-center  d-flex j-sb clazz border-bottom">
							<view class="">商品关键字</view>
							<view class="mr-2">
								<input type="text" placeholder="请输入商品关键字" @input="key_input" @blur="key_blur" @focus="key_focus" class="text-right" v-model="keywords" placeholder-class="font-29 mr-1 d-flex j-end"/>
							</view>
						</view>
						<view class=" py-3 a-center  d-flex j-sb clazz">
							<view class="">商品简单描述</view>
							<view class="mr-2">
								<input type="text" placeholder="请输入商品描述" @input="brief_input" @blur="brief_blur" @focus="brief_focus" class="text-right" v-model="goods_brief" placeholder-class="font-29 mr-1 d-flex j-end"/>
							</view>
						</view>
					</view>
				</view>
				
				<!-- <view class="mx-2 mb-2 bg-white rounded-20">
					<view class="ml-3">
						<view class="d-flex a-center clazz j-sb" :class="checked?'border-bottom':''">
							<view class="">是否包邮</view>
							<view class="mr-2">
								<u-switch v-model="basic_detail.is_shipping" size="43" @change="postage"></u-switch>
							</view>
						</view>
						<view class=" a-center clazz  d-flex j-sb " v-show="!basic_detail.is_shipping" @click="freight">
							<view class="">商品运费</view>
							<view class="d-flex j-center a-center mr-2">
								<text class="text-light-muted mr-2">{{freight_price?'固定模板['+freight_price+']':'去设置'}}</text>
								<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
							</view>	
						</view>
					</view>
				</view> -->
				</view>
			</scroll-view>
			<view class="bg-white release py-2 w-100 foot">
				<button type="warn" @click="rele">更新宝贝</button>
			</view>	
		<s-popup custom-class="demo-popup" position="bottom" v-model="pictureShow">
			<!-- 内容 -->
			<view class="m-2 bg-white rounded-20 icon_share">
				
				<view class="border-bottom d-flex ml-4 py-3 j-center a-center" @click="photos">
					<view class="">拍照</view>
				</view>
				<view class="d-flex ml-4 border-bottom py-3 j-center a-center" @click="album">
						<view class="">我的相册</view>
				</view>
				<view class="d-flex ml-4 py-3 j-center a-center" @click="previewImages">
					<view class="">预览图片</view>
				</view>
			</view>
			<view class="d-flex j-center a-center span-19 py-3 bg-white mx-2 my-1 rounded-25" @click="cancelShare">
				取消
			</view>
		</s-popup>
		
		<!-- 平台分类 -->
		<u-popup @close="clazz_popup" v-model="terrace" width="100%" height="80%" mode="bottom" border-radius="14" closeable="true" close-icon="close" close-icon-pos="top-right" close-icon-size="40">
			<view class="">
				<view class="eradders"></view>
				<view class="eradders position-fixed top-0  w-100 bg-white">
					<view class="py-2">
						<view class="font-md d-flex j-center a-center font-35">选择平台商品分类</view>
					</view>
					<view class="d-flex address" >
						<view class="py-3 mx-2" v-if="terrace_name" @click="one_tab">
							<view  class="" >{{terrace_name}}</view>
						</view>
						<view class="py-3 mx-2" v-if="terrace_one_name" @click="two_tab">
							<view class="">{{terrace_one_name}}</view>
						</view>
						<view class="py-3 mx-2" :class="three_show?'active_tab':''" v-if="terrace_two_name" @click="three_tab">
							<view class="">{{terrace_two_name}}</view>
						</view>
						<view class="ml-2 py-3 active_tab" @click="option_address" v-show="!three_show">请选择</view>
					</view>
				</view>
				<!-- 一级 -->
				<view v-show="terrace_one" class="content_address mx-2 py-2" v-for="(item,index) in oneClazz" :key="index" @click="clazz_one(item)">
						{{item.cat_name}}
				</view>
				<!-- 二级 -->
				<view v-show="terrace_two" class="content_address mx-2 py-2" v-for="(item,index) in twoClazz" :key="index" @click="clazz_two(item)">
						{{item.cat_name}}
				</view>
				<!-- 三级 -->
				<view v-show="terrace_three" class="content_address mx-2 py-2 d-flex j-sb" v-for="(item,index) in threeClazz" :key="index" @click="clazz_three(item)">
					<view class="" :class="item.cat_id==threeCatId?'active':''" >
						{{item.cat_name}}
					</view>
					<view class="" v-show="item.cat_id==threeCatId">
						<u-icon name="checkmark" color="#ff1515" size="33"></u-icon>
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 店铺分类 -->
		<u-popup @close="shopList_popup" v-model="shopping" width="100%" height="80%" mode="bottom" border-radius="14" closeable="true" close-icon="close" close-icon-pos="top-right" close-icon-size="40">
			<view class="">
				<view class="eradders"></view>
				<view class="eradders position-fixed top-0  w-100 bg-white">
					<view class="py-2">
						<view class="font-md d-flex j-center a-center font-35">选择店铺商品分类</view>
					</view>
					<view class="d-flex address" >
						<view class="py-3 mx-2" v-if="shopping_name" @click="shop_one_tab">
							<view  class="" >{{shopping_name}}</view>
						</view>
						<view class="py-3 mx-2" v-if="shopping_one_name" @click="shop_two_tab">
							<view class="">{{shopping_one_name}}</view>
						</view>
						<view class="py-3 mx-2" :class="shop_three_show?'active_tab':''" v-if="shopping_two_name" @click="shop_three_tab">
							<view class="">{{shopping_two_name}}</view>
						</view>
						<view class="ml-2 py-3 active_tab" @click="shop_option_address" v-show="!shop_three_show">请选择</view>
					</view>
				</view>
				<!-- 一级 -->
				<view v-show="shopping_one" class="content_address mx-2 py-2" v-for="(item,index) in oneShopping" :key="index" @click="shop_one(item)">
						{{item.cat_name}}
				</view>
				<!-- 二级 -->
				<view v-show="shopping_two" class="content_address mx-2 py-2" v-for="(item,index) in twoShopping" :key="index" @click="shop_two(item)">
						{{item.cat_name}}
				</view>
				<!-- 三级 -->
				<view v-show="shopping_three" class="content_address mx-2 py-2 d-flex j-sb" v-for="(item,index) in threeShopping" :key="index" @click="shop_three(item)">
					<view class="" :class="item.cat_id==shop_threeCatId?'active':''" >
						{{item.cat_name}}
					</view>
					<view class="" v-show="item.cat_id==shop_threeCatId">
						<u-icon name="checkmark" color="#ff1515" size="33"></u-icon>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { pathToBase64, base64ToPath } from '@/common/image-tools/index.js'
	import ImageCropper from "@/components/invinbg-image-cropper/invinbg-image-cropper.vue";
	import sPopup from '../../components/s-popup/index.vue';
	export default {
		components: {
			ImageCropper,
			sPopup
		},
		data() {
			return {
				checked:false,
				count:60,
				num:0,
				tempFilePath: '', // 图片地址
				cropFilePath: '', // 剪切地址
				clazzList:{
					cat_name:"",
					cat_id:""
				}, // 商品分类
				shopList:{
					cat_name:"",
					cat_id:""
				}, // 商家分类
				goods_name:"",// 名字
				prcie:"", // 价格
				cost_price:"", // 成本价
				store:"" ,// 库存
				pictureShow:false, // 添加图片模态框
				dictionaries:"", // 上传图片字典
				goods_id:'', // 商品ID
				basic_detail:'', // 商品详情
				userinfo:"", // 个人信息
				freight_price:"", // 运费
				
				goods_sn:"", // 商品货号
				bar_code:"", // 商品条形码
				goods_unit:'', // 商品单位
				keywords:"", // 关键字
				goods_brief:"", // 商品描述
				
				terrace:false, // 平台分类
				shopping:false ,// 店铺分类
				
				terrace_one:true,
				terrace_two:false,
				terrace_three:false,
				terrace_name:"", // 平台分类切换
				terrace_one_name:"", // 平台分类切换
				terrace_two_name:"", // 平台分类切换
				terraceClazz:[], // 全部列表
				oneClazz:[], // 1级平台分类
				twoClazz:[], // 2级平台分类
				threeClazz:[], // 3级平台分类
				subCatId:"", // cat_id标识符
				threeCatId:"", // 二级cat_id
				one_show:false,
				two_show:false,
				three_show:false,
				items_clazz:"",
				
				shopping_one:true,
				shopping_two:false,
				shopping_three:false,
				shopping_name:"", // 平台分类切换
				shopping_one_name:"", // 平台分类切换
				shopping_two_name:"", // 平台分类切换
				shoppingClazz:[], // 全部列表
				oneShopping:[], // 1级平台分类
				twoShopping:[], // 2级平台分类
				threeShopping:[], // 3级平台分类
				shop_subCatId:"", // cat_id标识符
				shop_threeCatId:"", // 二级cat_id
				shop_one_show:false,
				shop_two_show:false,
				shop_three_show:false,
				items_shopping:"",
				scrollHeight:0, // 自适应高度
				u_loadmore:true, // 加载中
			}
		},
		onReady() {
			let _this=this
			uni.getSystemInfo({
				success(resu) {
					const query = uni.createSelectorQuery()
					query.select('.scroll_header').boundingClientRect()
					query.select('.foot').boundingClientRect()
					query.exec(function(res) {
						_this.scrollHeight = resu.windowHeight - res[0].top - res[1].bottom+ 'px';
						console.log(res,resu)
					})
				}
			})
		},
		onLoad(e) {
			this.$H.post("admin/user/userinfo").then(res=>{
				this.userinfo=res.data
				console.log(res)
			})
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/detail",{goods_id:e.goods_id}).then(res=>{
				console.log(res)
				this.u_loadmore=false 
				this.basic_detail=res.data
				this.goods_name=this.basic_detail.goods_name
				this.prcie=this.basic_detail.shop_price.replace("￥",'')
				this.cost_price=this.basic_detail.cost_price
				this.store=this.basic_detail.stock
				this.clazzList.cat_id=this.basic_detail.category_id
				this.shopList.cat_id=this.basic_detail.merchant_category_id
				
				this.goods_sn=this.basic_detail.goods_sn // 商品货号
				this.bar_code=this.basic_detail.bar_code // 商品条形码
				this.goods_unit=this.basic_detail.goods_unit // 商品单位
				this.keywords=this.basic_detail.keywords // 关键字
				this.goods_brief=this.basic_detail.goods_brief // 商品描述
				
				if(this.basic_detail.merchant_category_name==""){
					this.basic_detail.merchant_category_name="请选择分类"
				}
				console.log(this.clazzList,this.shopList)
				this.num=this.basic_detail.goods_name.length
				// 运费
				if(!this.basic_detail.is_shipping){
					console.log(1)
					let num = parseInt(this.basic_detail.formated_goods_shipping_fee.replace("￥",'')).toFixed(1)
					this.freight_price= num
					var globalData = getApp().globalData.freight; //获取全局变量
					getApp().globalData.freight= num; //修改全局变量
				}else{
					console.log(2)
					return
				}
			})
			
			this.subCatId=1
			this.$H.post("admin/merchant/goods/category").then(res=>{
				this.terraceClazz=res.data
				this.terraceClazz.filter(v=>{
						return v.icon_show=false
				})
				// 一级
				this.oneClazz=this.terraceClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			})
			
			this.$H.post("admin/merchant/goods/merchant/category").then(res=>{
				this.shoppingClazz=res.data
				this.shoppingClazz.filter(v=>{
					return v.icon_show=false
				})
				this.oneShopping=this.shoppingClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			})
		},
		methods: {
			// 条形码
			scanCode(){
				let that=this
				uni.scanCode({
				    success: function (res) {
						that.bar_code=res.result
				    }
				});
			},
			// 商品货号
			sn_input(e){
				this.goods_sn=e.detail.value
			},
			sn_blur(e){
				if(e.detail.value==''){
					this.goods_sn=this.basic_detail.goods_sn
				}
			},
			sn_focus(e){
				this.goods_sn=""
			},
			// 商品货号
			bar_input(e){
				this.bar_code=e.detail.value
			},
			bar_blur(e){
				if(e.detail.value==''){
					this.bar_code=this.basic_detail.bar_code
				}
			},
			bar_focus(e){
				this.bar_code=""
			},
			// 商品货号
			unit_input(e){
				this.goods_unit=e.detail.value
			},
			unit_blur(e){
				if(e.detail.value==''){
					this.goods_unit=this.basic_detail.goods_unit
				}
			},
			unit_focus(e){
				this.goods_unit=""
			},
			// 商品货号
			key_input(e){
				this.keywords=e.detail.value
			},
			key_blur(e){
				if(e.detail.value==''){
					this.keywords=this.basic_detail.keywords
				}
			},
			key_focus(e){
				this.keywords=""
			},
			// 商品货号
			brief_input(e){
				this.goods_brief=e.detail.value
			},
			brief_blur(e){
				if(e.detail.value==''){
					this.goods_brief=this.basic_detail.goods_brief
				}
			},
			brief_focus(e){
				this.goods_brief=""
			},
			// 预览图片
			previewImages(){
				this.pictureShow=false;
				uni.previewImage({
					current: 1,
				    urls: this.cropFilePath?new Array(this.cropFilePath):new Array(this.basic_detail.img.url) // 图片路径必须是一个数组
				});
			},
			// 一级
			option_address(){
				this.terrace_one=true
				// 一级
				this.oneClazz=this.terraceClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			},
			// 商品分类
			goodsClass(){
				this.terrace=true
			},
			// 店铺商品分类
			goodsShop(){
				this.shopping=true
			},
			// 商品分类一级
			clazz_one(item){
				this.items_clazz=item
				this.terrace_name=item.cat_name
				this.terrace_one=false
				this.terrace_two=true
				// 二级
				this.twoClazz=this.terraceClazz.filter((v,index)=>{
					if(item.cat_id==v.parent_id){
						return v
					}
				})
			},
			// 商品分类二级
			clazz_two(item){
				this.items_clazz=item
				this.terrace_one_name=item.cat_name
				this.terrace_two=false
				this.terrace_three=true
				// 三级
				this.threeClazz=this.terraceClazz.filter((v,index)=>{
					if(item.cat_id==v.parent_id){
						return v
					}
				})
				console.log(this.threeClazz,item)
			},
			// 商品分类三级
			clazz_three(item){
				this.items_clazz=item
				this.three_show=true
				this.threeCatId=item.cat_id
				this.terrace_two_name=item.cat_name
				this.terrace=false
			},
			// 切换一级
			one_tab(){
				this.terrace_one=true
				this.terrace_two_name=""
				this.terrace_one_name=""
				this.three_show=false
				this.twoClazz=[]
				this.threeClazz=[]
				// 一级
				this.oneClazz=this.terraceClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			},
			// 切换二级
			two_tab(){
				this.terrace_one=false
				this.terrace_three=false
				this.three_show=false
				this.terrace_two=true
				this.terrace_two_name=""
			},
			
			clazz_popup(){
				this.clazzList=this.items_clazz
				console.log(this.clazzList,"关闭弹框")
			},
			
			
			// 店铺商品分类
			// 一级
			shop_option_address(){
				this.shopping_one=true
				// 一级
				this.oneShopping=this.shoppingClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			},
			// 商品分类一级
			shop_one(item){
				this.items_shopping=item
				this.shopping_name=item.cat_name
				this.shopping_one=false
				this.shopping_two=true
				// 二级
				this.twoShopping=this.shoppingClazz.filter((v,index)=>{
					if(item.cat_id==v.parent_id){
						return v
					}
				})
			},
			// 商品分类二级
			shop_two(item){
				this.items_shopping=item
				this.shopping_one_name=item.cat_name
				this.shopping_two=false
				this.shopping_three=true
				// 三级
				this.threeShopping=this.shoppingClazz.filter((v,index)=>{
					if(item.cat_id==v.parent_id){
						return v
					}
				})
			},
			// 商品分类三级
			shop_three(item){
				this.items_shopping=item
				this.shop_three_show=true
				this.shop_threeCatId=item.cat_id
				this.shopping_two_name=item.cat_name
				this.shopping=false
			},
			// 切换一级
			shop_one_tab(){
				this.shopping_one=true
				this.shopping_two_name=""
				this.shopping_one_name=""
				this.shop_three_show=false
				this.twoShopping=[]
				this.threeShopping=[]
				// 一级
				this.oneShopping=this.shoppingClazz.filter((item,index)=>{
					if(item.parent_id==0){
						return item
					}
				})
			},
			// 切换二级
			shop_two_tab(){
				this.shopping_one=false
				this.shopping_three=false
				this.shop_three_show=false
				this.shopping_two=true
				this.shopping_two_name=""
			},
			shopList_popup(){
				this.shopList=this.items_shopping
			},
			
	
			
			// 商品运费
			freight(){
				uni.navigateTo({
					url:"/pages/goods-freight/goods-freight"
				})
			},
			// 文本框
			change(e){
				if(e.detail.cursor<60){
					this.num=e.detail.cursor
					this.goods_name=e.detail.value
				}
			},
			// 
			chang_blur(e){
				if(e.detail.value==''){
					this.goods_name=this.basic_detail.name
				}
			},
			// 
			chang_focus(e){
				
				this.goods_name=""
			},
			// 价格
			add_price(e){
				this.prcie=e.detail.value
			},
			pri_blur(e){
				if(e.detail.value==''){
					this.prcie=this.basic_detail.shop_price.replace("￥",'')
				}
			},
			pri_focus(e){
				this.prcie=""
			},
			// 成本价
			cost_input(e){
				this.cost_price=e.detail.value
			},
			cost_blur(e){
				if(e.detail.value==''){
					this.cost_price=this.basic_detail.cost_price
				}
			},
			cost_focus(e){
				this.cost_price=""
			},
			// 库存
			add_store(e){
				this.store=e.detail.value
			},
			store_blur(e){
				if(e.detail.value==''){
					this.store=this.basic_detail.stock
				}
			},
			store_focus(e){
				this.store=""
			},
			
			// 上传图片
			unloadImg(){
				this.pictureShow = true;
			},
			// 取消
			cancelShare(){
				this.pictureShow = false;
			},
			// 拍照
			photos(){
				let that=this;
				uni.chooseImage({
				    count:1,
				    sizeType:["original","compressed"],
					sourceType: ['camera'], //从相册选择
				    success:(res)=>{
						console.log(res,"拍照")
						this.tempFilePath=res.tempFilePaths
						// res.tempFilePaths.forEach(v=>{
						// 	that.uploadFile(v);
						// })
					}
				});
				that.pictureShow=false;
			},
			// 我的相册
			album(){
				let that=this;
				uni.chooseImage({
				    count:1,
				    sizeType:["original","compressed"],
					sourceType: ['album'], //从相册选择
				    success:(res)=>{
						console.log(res,"我的相册")
						uni.showToast({
							title: "上传中...",
							icon: "loading",
							mask: true,
							duration: 5000,
                        });
						this.tempFilePath=res.tempFilePaths
					}
				});
				that.pictureShow=false;
			},
			uploadFile(filePath){
				uni.uploadFile({
					url:`${this.localConfig.web_Url}v2/store/medialibrary/image/temp/upload`,
					filePath:filePath,
					name:"tempimage",
					formData:{
						'token':uni.getStorageSync("token")
					},
					success: (res) => {
						let fileData=JSON.parse(res.data)
						console.log(fileData.data)
						this.dictionaries=fileData.data
					}
				})
			},
			// 裁剪图片
			confirm(e) {
			    this.tempFilePath = ''
			    this.cropFilePath = e.detail.tempFilePath
				this.uploadFile(this.cropFilePath)
			},
			toJSON(){
				return this
			},
			// 是否包邮
			postage(e){
				this.checked=e
				console.log(e)
				this.$H.post("admin/goods/toggle/free_shipping",{
					id:this.goods_id,
					is_free:this.basic_detail.is_shipping
				}).then(res=>{
					console.log(res)
				})
			},
			// 更新宝贝
			rele(){
				console.log(this.clazzList,this.shopList)
				if(this.userinfo.is_merchant){
					console.log(1)
					this.$H.post("admin/merchant/goods/update",{
						goods_id:this.goods_id, // 商品ID
						goods_name:this.goods_name, // 名字
						goods_price:this.prcie, // 价格
						cost_price:this.cost_price, // 成本价
						stock:this.store, // 库存
						goods_image:this.dictionaries, // 图片 字典
						is_shipping: this.checked, // 是否包邮
						category_id:this.clazzList.cat_id, //  平台商品分类
						merchant_category:this.shopList.cat_id ,// 商品分类
						
						goods_sn:this.goods_sn, // 商品货号
						bar_code:this.bar_code, // 商品条形码
						goods_unit:this.goods_unit, // 商品单位
						goods_keywords:this.keywords, // 关键字
						goods_brief:this.goods_brief, // 商品描述
						}).then(res=>{
							uni.navigateBack({
								delta:1
							})
							// 运费
							if(this.freight_price){
								let globalData = getApp().globalData.freight_template;
								console.log(globalData)
								this.$H.post("admin/goods/shipping/setting",{
									goods_id:res.data.goods_id,
									shipping_type:"fixed",
									shipping_fee:this.freight_price,
									template_id:globalData.template_id
								}).then(res=>{
									console.log(res)
									var globalData = getApp().globalData.freight; //获取全局变量
									getApp().globalData.freight= null; //修改全局变量
								})
							}
					})
				}else{
					this.$H.post("admin/merchant/goods/update",{
						goods_id:this.goods_id, // 商品ID
						goods_name:this.goods_name, // 名字
						goods_price:this.prcie, // 价格
						cost_price:this.cost_price, // 成本价
						stock:this.store, // 库存
						goods_image:this.dictionaries, // 图片 字典
						is_shipping: this.checked, // 是否包邮
						category_id:this.clazzList.cat_id, //  平台商品分类
						
						goods_sn:this.goods_sn, // 商品货号
						bar_code:this.bar_code, // 商品条形码
						goods_unit:this.goods_unit, // 商品单位
						keywords:this.keywords, // 关键字
						goods_brief:this.goods_brief, // 商品描述
						}).then(res=>{
							uni.navigateBack({
								delta:1
							})
							// 运费
							if(this.freight_price){
								let globalData = getApp().globalData.freight_template;
								console.log(globalData)
								this.$H.post("admin/goods/shipping/setting",{
									goods_id:res.data.goods_id,
									shipping_type:"fixed",
									shipping_fee:this.freight_price,
									template_id:globalData.template_id
								}).then(res=>{
									console.log(res)
									var globalData = getApp().globalData.freight; //获取全局变量
									getApp().globalData.freight= null; //修改全局变量
								})
							}
					})
				}
			}
		},
		onUnload() {
			var globalData = getApp().globalData.clazz; //获取全局变量
			getApp().globalData.clazz= null; //修改全局变量
			
			var globalData = getApp().globalData.shopClazz; //获取全局变量
			getApp().globalData.shopClazz= null; //修改全局变量
			
			var globalData = getApp().globalData.freight; //获取全局变量
			getApp().globalData.freight= null; //修改全局变量
		},
		onShow(){
			if(getApp().globalData.freight){
				let globalData = getApp().globalData.freight;
				if(globalData){
					this.freight_price=globalData
					console.log(this.freight_price)
				}
			}
				
			var clazz = getApp().globalData.clazz;
			var shopClazz = getApp().globalData.shopClazz;
			var globalDatas = getApp().globalData.release;
			console.log(globalDatas)
			if(globalDatas=="发布成功"){
				// this.shopList=null;
				// this.clazzList=null;
				this.goods_name='';
				this.prcie=null;
				this.store=null;
				this.checked=false;
				this.cropFilePath=null;	
				
				var globalData = getApp().globalData.release; //获取全局变量
				getApp().globalData.release= null; //修改全局变量
				
				var globalData = getApp().globalData.clazz; //获取全局变量
				getApp().globalData.clazz= null; //修改全局变量
				
				var globalData = getApp().globalData.shopClazz; //获取全局变量
				getApp().globalData.shopClazz= null; //修改全局变量
				
			}else if(clazz||shopClazz){
				if(clazz){
					this.clazzList=clazz
				}else{
					this.shopList=shopClazz
				}
				console.log(clazz,shopClazz)
			}
		}
	}
</script>

<style>
	.icon_gray{
		width: 220upx;
		height: 220upx;
	}
	.release /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
	.img{
		width: 100%;
		height: 100%;
	}
	.crop{
		overflow: hidden;
		width: 220upx;
		height: 220upx;
	}
	.footer{
		height: 145upx;
	}
	s-popup{
		z-index: 333;
	}
	.s-popup-mask{
		background: rgba(204,204,204,0.3)!important;
	}
	.content{
		background-color:rgb(237,237,237)!important;
		color: #666666;
	}
	.s-popup-wrap{
		background: rgba(204,204,204,0)!important;
	}
	.icon_share view{
		color: #888;
	}
	.icon_share image{
		width: 120upx;
		height: 120upx;
	}
	
	.drawing{
		position: absolute;
		bottom: 0;
		width: 100%;
		padding: 10upx 0;
		color: #FFFFFF;
		border-radius: 0 0 20upx 20upx;
		background-color: rgba(0,0,0,0.5);
		z-index: 111;
	}
	.address{
		border-bottom: 1px solid #eaeaea;
	}
	.content_address{
		height: 100%;
	}
	.eradders{
		height: 185upx;
	}
	.active_tab{
		color: #ff3333;
		border-bottom: 3px solid #ff3333;
	}
	.active{
		color: #ff3333;
	}
</style>
